<template>
  <div class="page-container">
    <div class="page-header">
      <button class="back-button" @click="goToHome">
        <span class="icon-arrow-left">←</span>
        返回首页
      </button>
      <div class="header-content">
        <h2>排班管理</h2>
        <p>管理和配置员工的工作排班计划</p>
      </div>
    </div>
    
    <div class="card">
      <div class="card-header">
        <h3>当前排班表</h3>
        <button class="btn-primary" @click="showAddModal = true">
          <span class="icon-plus">+</span> 添加排班
        </button>
      </div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="data-table">
            <thead>
              <tr>
                <th>员工姓名</th>
                <th>职位</th>
                <th>周一</th>
                <th>周二</th>
                <th>周三</th>
                <th>周四</th>
                <th>周五</th>
                <th>周六</th>
                <th>周日</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(schedule, index) in schedules" :key="index" class="table-row">
                <td>{{ schedule.name }}</td>
                <td>{{ schedule.position }}</td>
                <td v-for="(day, dayIndex) in schedule.days" :key="dayIndex">
                  <span :class="['shift', getShiftClass(day)]">{{ day }}</span>
                </td>
                <td class="action-buttons">
                  <button class="btn-action" @click="editSchedule(index)">编辑</button>
                  <button class="btn-action btn-danger" @click="deleteSchedule(index)">删除</button>
                </td>
              </tr>
              <tr v-if="schedules.length === 0">
                <td colspan="10" class="empty-state">
                  <div class="empty-icon">📅</div>
                  <p>暂无排班数据，请添加排班</p>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <!-- 添加/编辑排班弹窗 -->
    <div v-if="showAddModal" class="modal-backdrop">
      <div class="modal">
        <div class="modal-header">
          <h3>{{ editingIndex !== null ? '编辑排班' : '添加排班' }}</h3>
          <button class="modal-close" @click="showAddModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>员工姓名</label>
            <select class="form-control">
              <option>张三</option>
              <option>李四</option>
              <option>王五</option>
              <option>赵六</option>
            </select>
          </div>
          <div class="form-group">
            <label>职位</label>
            <select class="form-control">
              <option>技术支持</option>
              <option>客服专员</option>
              <option>运维工程师</option>
            </select>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label>周一</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
            <div class="form-group">
              <label>周二</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
            <div class="form-group">
              <label>周三</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label>周四</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
            <div class="form-group">
              <label>周五</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
            <div class="form-group">
              <label>周六</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
            <div class="form-group">
              <label>周日</label>
              <select class="form-control">
                <option>早班</option>
                <option>中班</option>
                <option>晚班</option>
                <option>休息</option>
              </select>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn-secondary" @click="showAddModal = false">取消</button>
          <button class="btn-primary" @click="saveSchedule">保存</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'RosterManage',
  data() {
    return {
      schedules: [
        {
          name: '张三',
          position: '技术支持',
          days: ['早班', '早班', '中班', '中班', '晚班', '休息', '休息']
        },
        {
          name: '李四',
          position: '客服专员',
          days: ['中班', '中班', '晚班', '晚班', '休息', '早班', '早班']
        },
        {
          name: '王五',
          position: '运维工程师',
          days: ['晚班', '晚班', '休息', '休息', '早班', '中班', '中班']
        }
      ],
      showAddModal: false,
      editingIndex: null
    }
  },
  methods: {
    goToHome() {
      this.$router.push('/home');
    },
    getShiftClass(shift) {
      return shift === '早班' ? 'morning' : 
             shift === '中班' ? 'afternoon' : 
             shift === '晚班' ? 'evening' : 'rest';
    },
    editSchedule(index) {
      this.editingIndex = index;
      this.showAddModal = true;
    },
    deleteSchedule(index) {
      if (confirm('确定要删除这条排班记录吗？')) {
        this.schedules.splice(index, 1);
      }
    },
    saveSchedule() {
      this.showAddModal = false;
      this.editingIndex = null;
    }
  }
}
</script>

<style scoped>
/* 基础样式与其他页面保持一致 */
.page-container {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  background: #f8fafc;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-content h2 {
  margin: 0 0 8px 0;
  color: #1e293b;
  font-size: 24px;
  font-weight: 600;
}

.header-content p {
  margin: 0;
  color: #64748b;
  font-size: 14px;
}

.back-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
}

.back-button:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.back-button:active {
  transform: translateY(0);
}

.card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  margin-bottom: 24px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  margin: 0;
  color: #1e293b;
  font-size: 18px;
  font-weight: 600;
}

.card-body {
  padding: 24px;
}

/* 表格样式 */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1000px;
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}

.data-table th {
  background-color: #f8fafc;
  font-weight: 600;
  color: #334155;
  position: sticky;
  top: 0;
  z-index: 10;
}

.table-row:hover {
  background-color: #f8fafc;
  transition: background-color 0.2s;
}

/* 班次标签 */
.shift {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.shift.morning {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.shift.afternoon {
  background: rgba(59, 130, 246, 0.1);
  color: #2563eb;
}

.shift.evening {
  background: rgba(139, 92, 246, 0.1);
  color: #7c3aed;
}

.shift.rest {
  background: rgba(148, 163, 184, 0.1);
  color: #64748b;
}

/* 按钮样式 */
.btn-primary {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
  font-weight: 500;
}

.btn-primary:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-action {
  background: #f1f5f9;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 6px;
  font-size: 13px;
  color: #334155;
  transition: all 0.2s ease;
}

.btn-action:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}

.btn-action:active {
  transform: scale(0.96);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.action-buttons {
  display: flex;
  gap: 6px;
}

/* 空状态样式 */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #64748b;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.7;
}

/* 弹窗样式 */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s;
}

.modal {
  background: white;
  border-radius: 10px;
  width: 90%;
  max-width: 800px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #64748b;
  transition: color 0.2s, transform 0.2s;
}

.modal-close:hover {
  color: #dc2626;
  transform: rotate(90deg);
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: #334155;
  font-weight: 500;
  font-size: 14px;
}

.form-control {
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: white;
  font-size: 14px;
  transition: all 0.2s ease;
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-group {
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-secondary:hover {
  background: #e2e8f0;
  transform: translateY(-2px);
}

.btn-secondary:active {
  transform: scale(0.98);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
</style>